/*
* Copyright (C) 2024-2025 Uniontech Technology Co., Ltd.
*
* Author:      zhangbingyi <zhangbingyi@uniontech.com>
*
* Maintainer:  zhangbingyi <zhangbingyi@uniontech.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "executingdialog.h"
#include "securitylevelchangedefinition.h"
#include "widgets/dspinner.h"

#include <QLabel>

#include <QHBoxLayout>

ExecutingDialog::ExecutingDialog(QWidget *parent)
    : DDialog(parent)
{
    setAccessibleName("executingDialog");

    initUI();
}

void ExecutingDialog::initUI()
{
    Qt::WindowFlags flags = windowFlags();
    flags |= Qt::WindowStaysOnTopHint;
    flags &= (~Qt::WindowCloseButtonHint);
    setWindowFlags(flags);
//    setWindowFlag(Qt::WindowStaysOnTopHint);
//    setWindowFlag(Qt::WindowCloseButtonHint, false);
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    setModal(true);
    setAttribute(Qt::WidgetAttribute::WA_DeleteOnClose);
    setIcon(QIcon::fromTheme(DIALOG_TIP_YELLOW));

    // 设置标题
    QLabel *title = new QLabel(this);
    title->setAccessibleName("executingDialog_title");
    title->setContentsMargins(0, 0, 0, 0);
    title->setText(tr("Set up security levels of your system"));
    QFont ft = title->font();
    ft.setBold(true);
    title->setFont(ft);
    addContent(title, Qt::AlignCenter);

    // 旋转控件
    DSpinner *spinner = new DSpinner(this);
    spinner->setAccessibleName("contentWidget_spinner");
    spinner->setFixedSize(20, 20);
    spinner->start();

    // 内容
    QLabel *label = new QLabel("", this);
    label->setAccessibleName("contentWidget_label");
    label->setText(tr("Switching the configuration of security levels..."));
    label->setAlignment(Qt::AlignCenter);

    // 中间控件
    QWidget *contentWidget = new QWidget(this);
    contentWidget->setAccessibleName("executingDialog_contentWidget");
    QHBoxLayout *hlayout = new QHBoxLayout;
    hlayout->addWidget(label);
    hlayout->addWidget(spinner);
    contentWidget->setLayout(hlayout);
    contentWidget->setContentsMargins(100, 10, 100, 30);

    addContent(contentWidget);
}
